package com.oracle.oa.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.oracle.oa.biz.MessageBiz;
import com.oracle.oa.biz.MessageToUserBiz;
import com.oracle.oa.biz.ReadCommonMessageBiz;
import com.oracle.oa.biz.impl.OperatelogBizImpl;
import com.oracle.oa.entity.Messagetouser;
import com.oracle.oa.entity.Readcommonmessage;
import com.oracle.oa.entity.Userinfo;

public class MessageToUserAction extends ActionSupport implements SessionAware {

	private List ckmtu;
	private Map<String, Object> session;
	MessageBiz mbiz;
	MessageToUserBiz mtubiz;
	ReadCommonMessageBiz rcmbiz;
	
	@Override
	public String execute() throws Exception {
		//删除选定的收件箱中的内容
		if(ckmtu!=null && ckmtu.size()>0){
			//判断是否有选中的复选框，若有选中的内容，循环取出
			for(int i = 0;i<ckmtu.size();i++){
				//得到发送消息对象信息的id
				long mtuid = Long.parseLong(ckmtu.get(i).toString());
				//得到消息发送对象整条信息
				Messagetouser mtu = (Messagetouser) mtubiz.getById(Messagetouser.class, mtuid);
				//得到用户已读信息的id
				List rcmlist = rcmbiz.getByProperty(Readcommonmessage.class, "message.messageid", mtu.getMessage().getMessageid());
				//若用户已读信息表中存在发送消息对象的集合，则删除集合
				if(rcmlist!=null && rcmlist.size()>0){
					Userinfo u = (Userinfo) session.get("userinfo");
					rcmbiz.deleteBymesAndUser(mtu.getMessage().getMessageid(), u.getUserid());
					OperatelogBizImpl.add("删除", "批量删除用户已读表中messageid为"+mtuid+"的数据");
				}
				mtubiz.delete(mtu);
				OperatelogBizImpl.add("删除", "删除消息发送对象中messageid为"+mtuid+"的消息");
			}
		}
		int type=2;
		session.put("type", type);
		return SUCCESS;
	}
	
	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;
	}

	public List getCkmtu() {
		return ckmtu;
	}

	public void setCkmtu(List ckmtu) {
		this.ckmtu = ckmtu;
	}

	public MessageToUserBiz getMtubiz() {
		return mtubiz;
	}

	public void setMtubiz(MessageToUserBiz mtubiz) {
		this.mtubiz = mtubiz;
	}

	public ReadCommonMessageBiz getRcmbiz() {
		return rcmbiz;
	}

	public void setRcmbiz(ReadCommonMessageBiz rcmbiz) {
		this.rcmbiz = rcmbiz;
	}

	public MessageBiz getMbiz() {
		return mbiz;
	}

	public void setMbiz(MessageBiz mbiz) {
		this.mbiz = mbiz;
	}

	
	
	
}
